package com.thinktank.controller;

import static com.thinktank.util.DbUtil.*;

import java.io.*;
import java.sql.*;

import javax.servlet.http.*;

import com.thinktank.dao.*;
import com.thinktank.vo.*;

public class NoticeEditProcessController implements Controller{
	public String execute(HttpServletRequest request, HttpServletResponse response) throws IOException{
		// 정보 인코딩 타입 정해서 받고
		request.setCharacterEncoding("utf-8");
		String seq = request.getParameter("seq");
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		content = content.replaceAll("\r\n", "<br />");
		
		// DB 접속해서 해당 노티스 받고
		Connection con = getConnection();
		NoticeDao dao = new NoticeDao(con);
		Notice notice = new Notice();
		notice = dao.getNotice(seq);
		
		// 수정사항 세팅해서
		notice.setSeq(seq);
		notice.setTitle(title);
		notice.setContent(content);
		
		//DB 업데이트
		int result = dao.update(notice);
		close(con);
		
		request.setAttribute("p", 2);
		if(result == 0){
			return "error.jsp";
		}
		
		
		return "redirect:noticeDetail.do?p=2&seq=" + seq;
	}

}
